package io.github.fb513.disk.api

import com.baomidou.mybatisplus.generator.FastAutoGenerator
import com.baomidou.mybatisplus.generator.config.*
import com.baomidou.mybatisplus.generator.config.rules.DateType
import java.util.*
import java.util.function.Function


private const val parentPackage = "my.mall.db"
private const val moduleName = "mall-db"
private const val url =
    "jdbc:mysql://fb513-test.rwlb.rds.aliyuncs.com:3306/mini_mall?useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&useSSL=false"
private const val username = "fb513"
private const val password = "$@!#4213rwqe"
private const val tablePrefix = "mall_"


fun main(args: Array<String>) {

    val projectPath = System.getProperty("user.dir")
    FastAutoGenerator.create(
        url,
        username,
        password
    )
        .globalConfig { builder: GlobalConfig.Builder ->
            builder.author("fengbo")
                .outputDir("$projectPath/${moduleName}/src/main/kotlin")
                .disableOpenDir()
                .dateType(DateType.TIME_PACK)
                .enableKotlin()
        }
        .packageConfig { builder: PackageConfig.Builder ->
            builder.parent(parentPackage)
                .entity("entity")
                .mapper("mapper")
                .pathInfo(
                    Collections.singletonMap<OutputFile, String>(
                        OutputFile.xml,
                        "$projectPath/${moduleName}/src/main/resources/mapper"
                    )
                )
        }
        .strategyConfig { scanner: Function<String?, String?>, builder: StrategyConfig.Builder ->
            builder.addInclude(
                scanner.apply("请输入表名，多个英文逗号分隔？所有输入")!!
            )
                .addTablePrefix(tablePrefix)
                .entityBuilder()
                .enableColumnConstant()
                .enableFileOverride()
                .disableSerialVersionUID()
                .mapperBuilder()
                .enableBaseResultMap()
                .enableBaseColumnList()
                .serviceBuilder()
                .disable()
                .convertServiceFileName { "" }
                .convertServiceImplFileName { "" }
                .controllerBuilder()
                .disable()
                .convertFileName{""}
        }
        .execute()
}